package com.example.carrierapp.ui.main.dispatch.detail.delivery

import android.content.Context

import com.example.carrierapp.base.BasePresenter
import com.example.carrierapp.bean.dispatch.DispatchDeliveryBean
import com.example.carrierapp.net.ApiMiddleHelper
import com.example.carrierapp.net.listener.DataCallBackListener
import com.example.carrierapp.util.LogUtil
import com.example.carrierapp.viewmodel.viewmodel.DispatchDeliverModel
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.reflect.TypeToken

import java.util.HashMap

import io.reactivex.Flowable

class DispatchDeliveryPresenter(private val mContext: Context) : BasePresenter<DispatchDeliveryContract.View>(), DispatchDeliveryContract.Presenter {

    override fun start() {

    }

    override fun getDispatchDetail(id: Int) {
        val biddingMap = HashMap<String, String>()
        biddingMap["id"] = id.toString() + ""
        val flowable = apiStrores.getDispatchDetails(biddingMap)

        ApiMiddleHelper.getInstance().toNetIo2Main(mContext, flowable, object : DataCallBackListener {
            override fun onSuccess(json: String) {
                LogUtil.d("getDispatchDetail-onSuccess-$json")
                view?.getDispatchDetailSuccess(Gson().fromJson<DispatchDeliverModel>(json, object : TypeToken<DispatchDeliverModel>() {}.type))
            }

            override fun onFailure(msg: String) {
                LogUtil.d("getDispatchDetail-onFailure-$msg")
                if (view != null) {
                    view.getDispatchDetailFailde(msg)

                }
            }
        })
    }
}
